# -*- coding: utf-8 -*-
'''
Created on 2020年5月9日

@author: Kitch
'''

import os
from configparser import ConfigParser
import logging

from models import *


config_file = "../example.ini" if os.path.exists("../example.ini") else "./example.ini"
config = ConfigParser()
config.read(config_file)


def init():
    # config the log & sqlalchemy
    logging.config.fileConfig(config_file)
    
    settings = {
        "sqlalchemy.url": config.get("main", "sqlalchemy.url"),
#         "sqlalchemy.pool_recycle": config.get("main", "sqlalchemy.pool_recycle"),    # for mysql
#         "sqlalchemy.pool_size": config.get("main", "sqlalchemy.pool_size"),    # for mysql
        }
    
    engine = engine_from_config(settings, 'sqlalchemy.')
    session.configure(bind=engine)
    Base.metadata.bind = engine
